package com.haierp.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.haierp.mapper.InventoryStockMapper;
import com.haierp.model.InventoryStock;
import com.haierp.service.IInventoryStockService;
import com.haierp.util.JsonPageResult;
import com.haierp.vo.InventoryQueryVO;

@Service("inventoryStockService")
public class InventoryStockServiceImpl extends SuperServiceImpl<InventoryStockMapper, InventoryStock>
		implements IInventoryStockService {
	@Autowired
	private InventoryStockMapper inventoryStockMapper;
	

	@Override
	public JsonPageResult<List<InventoryStock>> queryInventoryStock(InventoryQueryVO inventoryQueryVO) {
		JsonPageResult<List<InventoryStock>> inventoryStockResult = new JsonPageResult<>();
		// 1、查询总的记录数量
		Integer totalCount = inventoryStockMapper.queryInventoryStockCount(inventoryQueryVO);

		// 2、查询分页记录
		if (totalCount != null && totalCount != 0L) {
			inventoryStockResult.buildPage(totalCount, inventoryQueryVO);
			List<InventoryStock> inventoryStocks = inventoryStockMapper.queryInventoryStocks(inventoryQueryVO);
			inventoryStockResult.setData(inventoryStocks);
		} else {
			List<InventoryStock> inventoryStocks = new ArrayList<>();
			inventoryStockResult.setData(inventoryStocks);
		}
		return inventoryStockResult;
	}
}
